home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_08_03 / 8n03106a < prev    next >
Text File  |  1990-03-18  |  1KB  |  48 lines

  1. *****Listing 1*****
  2.  
  3. date_print3(date)
  4. date date;    /* internal date form */
  5. {
  6.     static struct datecache {
  7.         date internal;
  8.         printable_date external;
  9.         unsigned inuse : 1;
  10.     } dates[MAXDATEPRINTS];
  11.  
  12.     static struct datecache *d_last_used = dates;
  13.     static struct datecache *d_last_stored = dates;
  14.  
  15.     /* last one used is highly likely */
  16.     struct datecache *d = d_last_used;
  17.  
  18.     do {
  19.         if (d->internal == date) {
  20.             d_last_used = d;
  21.             d->inuse = TRUE;
  22.             return(d->external);
  23.         }
  24.         d = next_date(d);
  25.     } while (d != d_last_used);
  26.  
  27.     /* we have moved all the way around the buffer */
  28.     /* and didn't find it in cache */
  29.     /* find a new buffer */
  30.     d = next_date(d_last_stored);
  31.     do {
  32.         if (d->inuse) d->inuse = FALSE;
  33.         else break;
  34.     } while (d != d_last_stored);
  35.  
  36.     /* either found one not in use, or all in use */
  37.     d->inuse = FALSE; /* nec. if all are in use */
  38.     d_last_used = d;
  39.     d_last_stored = d;
  40.  
  41.     /* actually do the work and convert date */
  42.     /* into a printable representation */
  43.     .....
  44.     memcpy(d_last_used->external,....);
  45.     return(d_last_used->external);
  46. }
  47.  
  48.